# Created by 黄景涛
# DATE: 2025/4/14
import logging
from concurrent.futures import ThreadPoolExecutor


def async_main(config, _task, get_params_f, *task_args):
    """多线程入口函数"""

    # 配置日志格式
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(levelname)s - %(message)s'
    )

    # 线程池配置
    thread_count = config.get('thread_count', 5)

    # 创建线程池执行器
    with ThreadPoolExecutor(max_workers=thread_count) as executor:
        # 生成10个测试请求任务
        futures = []
        for i in range(config.get('task_count', 10)):
            params = get_params_f(i)
            futures.append(executor.submit(_task, params, *task_args))

        # 等待所有任务完成
        for future in futures:
            try:
                future.result()
            except Exception as e:
                logging.error(f"任务执行异常: {str(e)}")


if __name__ == '__main__':
    ...

